#include "DRListItem.h"
#include "ui_DRListItem.h"

DRListItem::DRListItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DRListItem)
{
    ui->setupUi(this);

    ui->pushButtonClose->hide();
    ui->labelAlert->hide();

    _index = -1;

    _alerm = false;
    if (_alerm)
    {
        ui->labelAlert->show();
    }
    else
    {
        ui->labelAlert->hide();
    }

    connect(ui->pushButtonClose, SIGNAL(clicked()), this, SLOT(deleteClicked()));
}

DRListItem::DRListItem(int index, QString text, QString time, bool alerm, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DRListItem)
{
    ui->setupUi(this);

    ui->pushButtonClose->hide();
    ui->labelAlert->hide();

    ui->labelTitle->setText(text);
    ui->labelTime->setText(time);

    _index = index;

    _alerm = alerm;
    if (_alerm)
    {
        ui->labelAlert->show();
    }
    else
    {
        ui->labelAlert->hide();
    }

    connect(ui->pushButtonClose, SIGNAL(clicked()), this, SLOT(deleteClicked()));
}

DRListItem::~DRListItem()
{
    delete ui;
}

void DRListItem::setText(QString text)
{
    ui->labelTitle->setText(text);
}

QString DRListItem::text()
{
    return ui->labelTitle->text();
}

void DRListItem::setTime(QString time)
{
    ui->labelTime->setText(time);
}

QString DRListItem::time()
{
    return ui->labelTime->text();
}

void DRListItem::setAlerm(bool alerm)
{
    _alerm = alerm;

    if (_alerm)
    {
        ui->labelAlert->show();
    }
    else
    {
        ui->labelAlert->hide();
    }
}

bool DRListItem::alerm()
{
    return _alerm;
}

int DRListItem::index()
{
    return this->_index;
}

void DRListItem::setText(int index)
{
    _index = index;
}

void DRListItem::deleteClicked()
{
    emit onDelete(_index);
}

void DRListItem::enterEvent(QEvent * event)
{
    ui->pushButtonClose->show();
}

void DRListItem::leaveEvent(QEvent * event)
{
    ui->pushButtonClose->hide();
}
